package com.lsh.user.controller;

import com.lsh.common.poi.ExcelUtil;
import com.lsh.common.util.AjaxResult;
import com.lsh.user.entity.UserInfo;
import com.lsh.user.repository.UserInfoRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author ：LiuShihao
 * @date ：Created in 2021/9/14 3:47 下午
 * @desc ：
 */
@RestController
public class ExcelController {

    @Autowired
    UserInfoRepository userInfoRepository;

    @GetMapping("/excel/allUser")
    public AjaxResult ExcelAllUser(){
        List<UserInfo> all = userInfoRepository.findAll();
        System.out.println("用户人数："+all.size());
        ExcelUtil<UserInfo> util = new ExcelUtil<UserInfo>(UserInfo.class);
        return util.exportExcel(all, "用户数据");
//        // 解决响应中文文件名乱码问题
//        String filename = URLEncoder.encode("用户信息表", "utf-8");
//        // 浏览器响应下载弹框
//        resp.setHeader("Content-disposition", "attachment;filename=" + filename + ".xls");
//        resp.setContentType("application/msexcel");
//        // 输出
//        OutputStream out = resp.getOutputStream();
//        wb.write(out);
//        out.close();

    }
}
